package com.ruoyi.web.controller.hotel;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.xc.hotel.entity.HotelRoomDetail;
import com.xc.hotel.service.HotelRoomDetailService;
import com.xc.hotel.service.HotelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hy
 * @version 1.0
 * @date 2020-11-20 13:20
 */
@Controller
@RequestMapping("hotel/room/detail")
public class HotelRoomDetailController extends BaseController{

    private final String prefix = "hotel/roomDetail";

    private HotelRoomDetailService hotelRoomDetailService;
    private HotelService hotelService;

    @GetMapping
    @RequiresPermissions("hotel:room:detail:view")
    public String view(@RequestParam Integer hotelId, ModelMap modelMap){
        modelMap.put("hotelId", hotelId);
        return prefix + "/table";
    }

    @GetMapping("add")
    @RequiresPermissions("hotel:room:detail:add")
    public String addView(@RequestParam Integer hotelId, ModelMap modelMap){
        modelMap.put("hotel", this.hotelService.getById(hotelId));
        return prefix + "/add";
    }

    @GetMapping("edit")
    @RequiresPermissions("hotel:room:detail:edit")
    public String editView(@RequestParam Integer id, ModelMap modelMap){
        modelMap.put("hotelId", this.hotelRoomDetailService.getById(id));
        return prefix + "/edit";
    }

    @GetMapping("edit/{id}")
    @RequiresPermissions("hotel:room:detail:edit")
    public String editLine(@PathVariable Integer id, ModelMap modelMap){
        modelMap.put("hotelId", this.hotelRoomDetailService.getById(id));
        return prefix + "/edit";
    }

    @PostMapping("list")
    @RequiresPermissions("hotel:room:detail:view")
    @ResponseBody
    public TableDataInfo list(@RequestParam Integer hotelId){
        LambdaQueryWrapper<HotelRoomDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HotelRoomDetail::getHotelId, hotelId);
        startPage();
        final List<HotelRoomDetail> list = this.hotelRoomDetailService.list(queryWrapper);
        return getDataTable(list);
    }

    @PostMapping("add")
    @RequiresPermissions("hotel:room:detail:add")
    @ResponseBody
    public AjaxResult add(HotelRoomDetail hotelRoomDetail){
        //hotelRoomDetail.setStatus(0);
        this.hotelRoomDetailService.save(hotelRoomDetail);
        return AjaxResult.success();
    }

    @PostMapping("remove")
    @RequiresPermissions("hotel:room:detail:remove")
    @ResponseBody
    public AjaxResult remove(@RequestParam List<Integer> ids){
        this.hotelRoomDetailService.removeByIds(ids);
        return AjaxResult.success();
    }
    @PostMapping("edit")
    @RequiresPermissions("hotel:room:detail:edit")
    @ResponseBody
    public AjaxResult edit(HotelRoomDetail hotelRoomDetail){
        this.hotelRoomDetailService.updateById(hotelRoomDetail);
        return AjaxResult.success();
    }

    @Autowired
    public void setHotelRoomDetailService(HotelRoomDetailService hotelRoomDetailService) {
        this.hotelRoomDetailService = hotelRoomDetailService;
    }

    @Autowired
    public void setHotelService(HotelService hotelService) {
        this.hotelService = hotelService;
    }
}
